package com.hongruan.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.hongruan.bean.Menu;
import com.hongruan.dao.MenuDao;

@Repository
public class MenuDaoImpl extends GenericDaoHibernateImpl<Menu, Long> implements MenuDao {
	public MenuDaoImpl() {
		super(Menu.class);
	}

	@SuppressWarnings("unchecked")
	public List<Menu> getMenuList(Integer level) {
		String hql = "from Menu m where m.menuLevel=:level";
		Query query = this.getCurrentSession().createQuery(hql);
		query.setInteger("level", level);
		
		return query.list();
	}
	
	@SuppressWarnings("unchecked")
	public List<Menu> getMenuListById(Long id){
		String hql = "select m.formId,m.name from t_menu m right join "+
					"(select mm.childMenu_id id from t_menu_t_menu mm where mm.t_menu_id = :id) a "+
					"on a.id = m.id";
		Query query = this.getCurrentSession().createSQLQuery(hql);
		query.setParameter("id", id);
		return query.list();
	}
}
